package com.chuiyuan.study;

import java.math.BigInteger;
import java.util.concurrent.BlockingQueue;

/**
 * Created by chuiyuan on 2/21/16.
 */
public class PrimeProduce extends Thread{
    private final BlockingQueue<BigInteger> queue;

    PrimeProduce(BlockingQueue<BigInteger> queue){
        this.queue = queue;
    }

    public void run(){
        try {
            BigInteger p = BigInteger.ONE;
            while(!Thread.currentThread().isInterrupted()){
                queue.put(p.nextProbablePrime());
            }
        }catch (InterruptedException e ){}
    }

    public void cancel(){
        interrupt();
    }
}
